package function;

import com.alibaba.fastjson2.JSONObject;
import net.UDPClient;

import javax.swing.*;

/**
 * 检查用户名是否合法
 * 发送：
 * {
 * "function":"agreeFriendApply",
 * "username":"12345",
 * "targetUsername", "zyz",
 * "sendTime":1716713581033
 * }
 * 无返回
 **/
public class AgreeFriendApply {
    public static final void send(String username, String targetUsername) {
        Object[] options = {"拒绝", "同意"};
        int choose = JOptionPane.showOptionDialog(null, "是否同意" + targetUsername + "的好友申请", "好友申请", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        if (choose == 1) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("function", "agreeFriendApply");
            jsonObject.put("username", username);
            jsonObject.put("targetUsername", targetUsername);
            UDPClient.send(jsonObject);
        }
        System.out.printf("已%s%s好友申请\n", choose==1?"同意":"拒绝", targetUsername);
    }
}
